package org.getOffer.offer27;

/**
 * @Author yu
 * @Date 2021/10/7
 */
public class Solution {

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(4);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(7);
        TreeNode treeNode4 = new TreeNode(1);
        TreeNode treeNode5 = new TreeNode(3);
        TreeNode treeNode6 = new TreeNode(6);
        TreeNode treeNode7 = new TreeNode(9);

        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode2.left = treeNode4;
        treeNode2.right = treeNode5;
        treeNode3.left = treeNode6;
        treeNode3.right = treeNode7;

        Solution solution = new Solution();
        TreeNode treeNode = solution.mirrorTree(treeNode1);

        System.out.println(treeNode);

    }

    TreeNode temp = null;

    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        temp = root.left;
        root.left = root.right;
        root.right = temp;

        this.mirrorTree(root.left);
        this.mirrorTree(root.right);

        return root;
    }

}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}